import { createElement, HTMLAttributes, type FC } from 'react';
import classNames from 'classnames';

import { adDefaultProps } from './defaultProps';
import type { AdOptions } from './type';

export interface AdProps extends AdOptions, HTMLAttributes<HTMLDivElement> {}

const Ad: FC<AdProps> = (props) => {
  const { className, unit, test, children, forwardedRef, ...adProps } = props;

  return createElement(
    'div',
    {
      ref: forwardedRef,
      className: classNames('ui', unit, { test }, 'ad', className),
      'data-text': typeof test === 'string' ? test : undefined,
      ...adProps,
    },
    children,
  );
};

Ad.displayName = 'Ad';
Ad.defaultProps = adDefaultProps;

export default Ad;
